import http from '@/config/request'
import {
	baseUrl
} from "@/config/index";
import {
	state
} from '@/stores/app-store'

// 登录
export function workerLogin(data) {
	return http.post(baseUrl + `/h5/user/workerLogin`, data);
}

// 核验门票
export function verTick(data) {
	return http.post(baseUrl + `/h5/user/verTick`, data);
}

// 票据信息
export function tickInfo(data) {
	return http.get(baseUrl + `/h5/user/tickInfo`, data);
}

// 核验记录
export function myVerTickList(data) {
	return http.get(baseUrl + `/h5/user/myVerTickList`, data);
}








// 上传头像校验
export function auditInfo(data) {
	return http.post(baseUrl + `/app/system/auditInfo`, data);
}

// 上传图片
export const selectImg = async function(data, callback) {
	let files;
	let options = {};
	uni.showLoading({
		title: '加载中...',
		mask: true,
	})
	try {
		files = data
		uni.uploadFile({
			url: baseUrl + '/app/system/upload',
			filePath: files,
			name: 'file',
			header: {
				// token用户登录的唯一凭证
				Authorization: 'Bearer' + state.token
			},
			success: (uploadFileRes) => {
				if (uploadFileRes.statusCode == 200) {
					uni.hideLoading()
					uni.showToast({
						title: '上传成功！',
						icon: 'none'
					});
					var newData = JSON.parse(uploadFileRes.data)
					callback(newData.data.url);
				} else {
					uni.hideLoading()
					uni.showToast({
						title: '图片上传失败，稍后重试！',
						icon: 'none'
					})

				}
			},
			fail: (res) => {
				uni.hideLoading()
				uni.showToast({
					title: '图片上传失败，稍后重试！',
					icon: 'none'
				})
			},

		});
	} catch (err) {
		console.log(err)
	}
}